package com.memo.asynctasks;

import java.util.Date;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;

import com.memo.App;
import com.memo.PickDayActivity;
import com.memo.R;
import com.memo.db.DAO;

public class DBTask extends AsyncTask<Void, Boolean, Boolean>{
	private Activity act;
	private ProgressDialog dialog;
	private Date date;
	private App app;
	
	public DBTask(Activity act, Date date) {
		this.act = act;
		this.date = date;
		app = (App) act.getApplication();
	}

	
	@Override
	protected void onPreExecute() {
		dialog = ProgressDialog.show(act, "", act.getString(R.string.db_wait_msg));
		super.onPreExecute();
	}


	@Override
	protected Boolean doInBackground(Void... params) {
		try{
			app.setCongs(DAO.getGreatingsByDay(act, date));
		}catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	protected void onPostExecute(Boolean result) {	
		super.onPostExecute(result);
		dialog.dismiss();
		Intent intent = new Intent();
        intent.setClass(act, PickDayActivity.class);
        act.startActivity(intent);
	}
	

}
